#include "tvoeradio.h"

#ifdef Q_WS_WIN

#include <windows.h>

#define MMKeyPlay 0xB3
#define MMKeyStop 0xB2
#define MMKeyNext 0xB0

#define MMKeyPlayID 1
#define MMKeyStopID 2
#define MMKeyNextID 3

void TvoeRadio::constructOp()
{
    RegisterHotKey(m_mainWindow.winId(), MMKeyPlayID, 0, MMKeyPlay);
    RegisterHotKey(m_mainWindow.winId(), MMKeyStopID, 0, MMKeyStop);
    RegisterHotKey(m_mainWindow.winId(), MMKeyNextID, 0, MMKeyNext);
}

void TvoeRadio::destructOp()
{
    UnregisterHotKey(m_mainWindow.winId(), MMKeyPlayID);
    UnregisterHotKey(m_mainWindow.winId(), MMKeyStopID);
    UnregisterHotKey(m_mainWindow.winId(), MMKeyNextID);
}

bool TvoeRadio::winEventFilter(MSG *m, long *result)
{

    if(m->message != WM_HOTKEY)
        return false;

    switch (m->wParam) {

    case MMKeyPlayID:
        m_mainWindow.playPause();
        return true;

    case MMKeyStopID:
        m_mainWindow.stop();
        return true;

    case MMKeyNextID:
        m_mainWindow.next();
        return true;

    }
    return false;
}

#endif
